<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>多个ELF文件分析</title>
<link rel="stylesheet" href="../styles/style.css" type="text/css" />
<link rel="stylesheet" href="../styles/table.css" type="text/css" />
<script src="../script/common.js"></script>
<script type="text/javascript">
$import("rpc.js");
$import("table_list_dynamic_appended.js");

var suffixList;
var fileList;
var fileTotal;
var completed;
var status;


/** 变量初始化 */
function init()
{
	suffixList = new Array();
	fileList = new Array();
	fileTotal = 0;
	completed = false;
	status = null;
}

function onSubmit()
{
	init();

	if ($("folderPath").value == "")
	{
		alert("请选择要分析的zip文件包！");
		return;
	}

	var callback = function()
	{
		$("fileForm").submit();
		check();				//检查文件上传进度，完成后开始PE文件分析
	}
	$("progress").style.display = "";
	$("finish").style.display = "none";

	var operation = new Operation("文件.准备上载文件");
	operation.path = "";
	operation.execute(callback);
}

/** 检查上载进度 */
function check()
{
	var callback = function (result)
	{
		if (completed) return;

		status = result.status;
		if (status != null)
		{
			if (status.aborted)
			{
				completed = true;
				alert("上载被取消: " + status.reason);
				status = null;
				return;
			}
			if (status.completed)
			{
				completed = true;
				$("progress").style.display = "none";
				status = null;
				loadFiles();
				return;
			}
		}
		setTimeout(check, 1000);
	}
	
	var operation = new Operation("文件.获取上载进度");
	operation.execute(callback);
}

function loadFiles()
{
	var callback = function(o)
	{
		fileList = o.fileList;
		fileTotal = fileList.length;
		ELFAnalyzer();
	};
	
	var operation = new Operation("ELF分析.装载多文件分析目录");
	operation.folderPath = $("folderPath").value;
	operation.isDepth = $("yesDir").checked;
	operation.execute(callback);
}

function ELFAnalyzer()
{
	$("status").style.display = "";				//分析状态条
	var operations1 = 
	[
		{icon: "../images/icon_view.gif", text: "查看结果", onclick: onOpen}
	];
	var operations2 = 
	[
		{icon: "../images/icon_not_allow.gif", text: "查看结果", onclick: onError}
	];
	var titles = 
	[
		{text:"文件路径", width:"30%"},
		{text:"大小", width:"20%"},
		{text:"状态", width:"30%"},
		{text:"操作", width:"10%"}
	];
	var columns =  
	[
		function(data) { return data.path;},
		function(data) { return data.size; },
		function(data) { return data.status; },
		function(data) { 		
			return (data.status == "分析完成" ? AppendTableList.links(operations1, data) : AppendTableList.links(operations2, data)); 
			}
	]; 

	var operation = new Operation("ELF分析.分析多个文件");
	var appendTableList = new AppendTableList(operation, titles, columns, fileTotal);
	appendTableList.create($("container"));
	appendTableList.append(fileList);
}

function onOpen(data)
{
	window.open("../peResult/" + data.parentFolder + "/" + data.name + ".html", "_blank");
}

function onError(data)
{
	alert(data.path + "不是有效的ELF文件！");
}

/** 设置路径输入框的提示信息 */
//function addListener(element,e,fn)
//{   
//	if(element.addEventListener)
//    {   
//    	element.addEventListener(e,fn,false);   
//    } 
//    else 
//    {   
//        element.attachEvent("on" + e,fn);   
//    }   
//}
//
//function onLoad()
//{
//	var myinput = $("folderPath");
//	addListener(myinput,"click",function(){
//		if (myinput.value == "路径名类似:C:/peFiles/test")
//			myinput.value = "";
//		});
//	addListener(myinput,"blur",function(){
//		if (myinput.value == "")
//			myinput.value = "路径名类似:C:/peFiles/test";
//		});
//}
</script>

</head>
<body>
<div id="ur_here"><img src="../images/icon_here.gif" style="align:absmiddle" align="absmiddle"/> 当前位置：首页 » 多个ELF文件分析 </div>
<div id="wrap">
<div id="containaer" >
	<div class="filter">
		<div class="filterTitle">
				<table cellpadding=0 cellspacing=0 border=0 width="100%" style="border-right:1px solid #A7B9CF;">
					<tr class='tablecell'>
						<td class='tit' width="20%">选择待分析的zip压缩文件</td>
						<td class='inp'>
							<form id="fileForm" name="fileForm" action = "../upload" method="post" enctype="multipart/form-data" target="upload_result">
								<input id="folderPath" name="folderPath" type="file" size="40"/>
								<span style="color:red">&nbsp;&nbsp;*请将要分析的文件夹打包为zip格式上传</span>
							</form>
							<iframe name="upload_result" id="upload_result" style="display:none"></iframe>	
						</td>
					</tr>
					<tr class='tablecell'>
						<td class='tit'>是否分析子目录</td>
						<td class='inp'>
							<input id="yesDir" name="dirSelect" type="radio" class="form_input" />是
							<input id="noDir" name="dirSelect" type="radio" checked class="form_input" />否
						</td>
					</tr>
				</table>
		</div>
		<div class="filterInput" style="padding:28px 0px 0px 25px;">
				<input type="button" class="pe_result" onClick="onSubmit()"/>
				<span id="progress" style="display:none">文件分析中...&nbsp;<img src="../images/loading.gif"></span>
		</div>
		<div class="clear"></div>
	</div>
	<div class="title" id="status" style="display:none">
			正在分析文件:<span id="statusBar"></span>&nbsp;<img src="../images/loading.gif">请等待...
	</div>
	<div class="title" id="finish" style="display:none">
			恭喜你！目录中文件全部分析完成！
	</div>
	
	<div id="container"></div>
</div>
</div>
</body>
</html>